import com.sun.prism.impl.shape.BasicRoundRectRep;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * Author: WJW
 * Date: 2024-07-27
 * Time: 23:24
 */
public class Test {
    //统计每个数据出现的次数
    public static void main(String[] args) {
        int[] array = {1,2,3,4,2,3,4};
        Map<Integer,Integer> map = new HashMap<>();
        for (Integer x : array){
            if(map.get(x) == null){
                //第一次存放
                map.put(x,1);
            }else {
                //其他情况在原来的基础上+1
                int val = map.get(x);
                map.put(x,val+1);
            }
        }
        for (Map.Entry<Integer,Integer> entry:map.entrySet()){
            System.out.println("key: "+entry.getKey()+"val: "+entry.getValue());
        }
    }


    //去除重复的数据，重复的数据只保留一份
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,2,3};
        HashSet<Integer> set = new HashSet<>();
        for (int i = 0; i < array.length; i++) {
            set.add(array[i]);
        }
        System.out.println(set);
    }


}
